// pages/transfer/transfer.js
import dayjs from "dayjs";
import { getUnDisposePartsCount } from "../../api/tansfer";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: "1",
    alreadyRender: {// 初始时只加载一个页签内容
      1: true,
      2: false,
      3: false,
      4: false,
    },
    transferPartsTitle: '中转配件',
  },

  onChange(event) {
    this.data.alreadyRender[event.detail.name] = true
    this.setData({
      active: event.detail.name,
      alreadyRender: this.data.alreadyRender
    })
  },

  // 加载中转配件数量
  getUnDisposePartsCount(params) {
    getUnDisposePartsCount(params).then(res => {
      this.setData({transferPartsTitle: `中转配件(${res.data.result || 0})`})
    })
  },

  // 子组件获取配件数量
  getCountFromPart(event) {
    this.getUnDisposePartsCount(event.detail)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getUnDisposePartsCount({
      timeStart: dayjs().format('YYYY-MM-DD 00:00:00'),
      timeEnd: dayjs().format('YYYY-MM-DD 23:59:59'),
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    const cakelCom = this.selectComponent('#transferCake')
    const recordCom = this.selectComponent('#transferRecord')
    const partsCom = this.selectComponent('#transferParts')
    const abnormalCom = this.selectComponent('#transferAbnormal')
    if (this.data.active == 1) {
      cakelCom.onPullDownRefresh()
    } else if (this.data.active == 2) {
      recordCom.onPullDownRefresh()
    } else if (this.data.active == 3) {
      partsCom.onPullDownRefresh()
    } else if (this.data.active == 4) {
      abnormalCom.onPullDownRefresh()
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    const abnormalCom = this.selectComponent('#transferAbnormal')
    if (this.data.active == 3) {
      abnormalCom.onReachBottom()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },


})